import { SSeqPlayerItem } from "../../../../../Message/Public/SSeqPlayerItem";
import { Global } from "../../../../../com/gengine/global/Global";
import { LayerManager } from "../../../manager/LayerManager";
import { DisplayUtil } from "../../../../common/DisplayUtil";
import { BaseItem } from "../../common/BaseItem";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
import { SPlayerItem } from "../../../../../Message/Public/SPlayerItem";
import { ItemData } from "../../../resource/info/ItemData";
import { SWFPlayer } from "../../../scene/modle/SWFPlayer";
import { Language } from "../../../../../extend/language/Language";
import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { ModelType } from "../../../scene/modle/data/ModelType";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class Lv70OpShowBonus
    
    export  class Lv70OpShowBonus /* flash.display.Sprite */
    {
        constructor()
        {
            
            this.initView();
            this._btn.addEventListener(flash.events.MouseEvent.CLICK, this.clickGetBonusHandler);
            return;
        }

        public dispose(): void
        {
            if (this._bg != null) 
            {
                this._bg.dispose();
                this._bg = null;
            }
            return;
        }

        public get step(): int
        {
            return this._step;
        }

        public set step(arg1: int)
        {
            this._step = arg1;
            return;
        }

        public show(arg1: SSeqPlayerItem, arg2: Function): void
        {
            this.reLoadBg();
            this._callback = arg2;
            this.x = (Global.stage.stageWidth - 420) / 2;
            this.y = (Global.stage.stageHeight - 220) / 2;
            LayerManager.windowLayer.addChild(this);
            this.updateBonusItem(arg1);
            return;
        }

        public middlePlace(): void
        {
            this.x = (Global.stage.stageWidth - 420) / 2;
            this.y = (Global.stage.stageHeight - 220) / 2;
            return;
        }

        public hide(): void
        {
            DisplayUtil.removeMe(this);
            this._callback = null;
            return;
        }

        public isHide(): Boolean
        {
            return this.parent == null;
        }

        /* internal  */clickGetBonusHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (this._callback != null) 
            {
                this._callback.apply();
            }
            return;
        }

        /* internal  */updateBonusItem(arg1: SSeqPlayerItem): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc6=null;
            if (this._names == null || this._names.length < arg1.playerItem.length) 
            {
                if (this._names == null) 
                {
                    this._names = [];
                    this._items = [];
                }
                loc3 = this._names.length;
                while (loc3 < arg1.playerItem.length) 
                {
                    loc1 = new BaseItem();
                    (loc4 = GlobalClass.getBitmap(ImagesConst.PackItemBg)).x = -3;
                    loc4.y = -3;
                    loc1.addChildAt(loc4, 0);
                    loc1.width = 32;
                    loc1.height = 32;
                    loc1.isDragAble = false;
                    loc1.isDropAble = false;
                    loc1.x = loc3 * 106;
                    loc1.y = 0;
                    this._spItem.addChild(loc1);
                    loc2 = ObjCreate.createGTextField("", loc3 * 106 - 34, 40, 106, 20, this._spItem);
                    (loc5 = loc2.defaultTextFormat).align = flash.text.TextFormatAlign.CENTER;
                    loc2.defaultTextFormat = loc5;
                    this._names.push(loc2);
                    this._items.push(loc1);
                    ++loc3;
                }
            }
            loc3 = 0;
            while (loc3 < this._names.length) 
            {
                loc2 = this._names[loc3] as GTextFiled;
                loc1 = this._items[loc3] as BaseItem;
                if (loc3 >= arg1.playerItem.length) 
                {
                    loc2.visible = false;
                    loc1.visible = false;
                }
                else 
                {
                    loc6 = arg1.playerItem[loc3] as SPlayerItem;
                    loc1.itemData = new ItemData(loc6.itemCode);
                    loc1.amount = loc6.itemAmount;
                    loc2.htmlText = loc1.itemData.htmlName;
                }
                ++loc3;
            }
            return;
        }

        /* internal  */loadSWFCompleted(arg1: SWFPlayer): void
        {
            if (arg1.movieClipData != null) 
            {
                arg1.movieClipData.isClear(false);
            }
            return;
        }

        /* internal  */initView(): void
        {
            this._btn = ObjCreate.createGButton("", 183, 167, 77, 28, this, "ButtonRed");
            this._btn.label = Language.getString(20424);
            this._spItem = new Object /* flash.display.Sprite */();
            this._spItem.x = 98;
            this._spItem.y = 86;
            this.addChild(this._spItem);
            return;
        }

        /* internal  */reLoadBg(): void
        {
            if (this._bg == null) 
            {
                this._bg = ObjectPool.getObject(SWFPlayer);
                this._bg.move(200, 200);
                this._bg.loadComplete = this.loadSWFCompleted;
                this._bg.load("Lv70DramaBonusBg.swf", ModelType.NormalSwf, null);
                this.addChildAt(this._bg, 0);
            }
            return;
        }

        /* internal */ /* var */_btn: GButton;

        /* internal */ /* var */_callback: Function;

        /* internal */ /* var */_items: Array<any>;

        /* internal */ /* var */_names: Array<any>;

        /* internal */ /* var */_spItem: Object /* flash.display.Sprite */;

        /* internal */ /* var */_step: int;

        /* internal */ /* var */_bg: SWFPlayer;
    }
